#ifndef SCREENIMAGEPROVIDER_H
#define SCREENIMAGEPROVIDER_H
#include <QQuickImageProvider>
#include <QImage>
#include <QSize>
#include <QColor>
class ScreenImageProvider : public QQuickImageProvider
{
public:
    ScreenImageProvider()
        : QQuickImageProvider(QQuickImageProvider::Pixmap)
    {
    }

    QPixmap  requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)//这个是自动调用的。路径"image://screen"，如需要使用id等参数，如"image://screen/id"等
    {
        int width = 160;
        int height = 100;

        if(size)
            *size = QSize(width,height);
        QPixmap pixmap(requestedSize.width() > 0 ? requestedSize.width() : width,
                       requestedSize.height() > 0 ? requestedSize.height() : height);
        pixmap.fill(QColor("blue").rgba());
        return pixmap;
    }
    QImage img;
};
#endif // SCREENIMAGEPROVIDER_H
